#include <stdio.h>

int main() {
    int n, sum = 0;
    printf("Please enter a positive number: ");
    while (scanf("%d", &n) != 1 || n <= 0) {  // 输入验证，确保输入是正数
        printf("Invalid input. Please enter a positive number: ");
        while (getchar() != '\n'); // 清空输入缓冲区
    }
    printf("You entered: %d\n", n);

    printf("Calculating the sum of numbers from 1 to %d...\n", n);

    int i=1; // 声明变量i

    // 计算从1到n的数字的总和
    for (;;) {
        sum += i;  // 累加计算总和
        printf("Adding %d\n", i); // 打印每步的累加过程
        i++;
        if (i > n) {
            break; // 退出循环
        }
    }

    while(i<n){
        printf("Adding %d\n", i); // 打印每步的累加过程
    }
    // printf i value

    printf("The value of i is: %d\n", i); // 打印i的最终值
    
    printf("The sum of numbers from 1 to %d is: %d\n", n, sum);  // 打印总和
    return 0;
}
